package battle.gameplay;

import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;

public class Direction{
	public static final float aSouth = 0;
	public static final float aEast = FastMath.HALF_PI;
	public static final float aNorth = FastMath.PI;
	public static final float aWest = FastMath.HALF_PI * 3;
	
	public static final Vector3f vSouth = new Vector3f(0, 0, 1);
	public static final Vector3f vEast = new Vector3f(1, 0, 0);
	public static final Vector3f vNorth = new Vector3f(0, 0, -1);
	public static final Vector3f vWest = new Vector3f(-1, 0, 0);
	
	public static final int iSouth = 0;
	public static final int iEast = 1;
	public static final int iNorth = 2;
	public static final int iWest = 3;
	
	public static int index(float dir){
		if (dir == aSouth)
			return iSouth;
		if (dir == aEast)
			return iEast;
		if (dir == aNorth)
			return iNorth;
		if (dir == aWest)
			return iWest;
		return -1;
	}
	
	public static int index(Vector3f dir){
		if (dir.equals(vSouth))
			return iSouth;
		if (dir.equals(vEast))
			return iEast;
		if (dir.equals(vNorth))
			return iNorth;
		if (dir.equals(vWest))
			return iWest;
		return -1;
	}
	
	public static float angle(int dir){
		if (dir == iSouth)
			return aSouth;
		if (dir == iEast)
			return aEast;
		if (dir == iNorth)
			return aNorth;
		if (dir == iWest)
			return aWest;
		return -1;
	}
	
	public static float angle(Vector3f dir){
		if (dir.equals(vSouth))
			return aSouth;
		if (dir.equals(vEast))
			return aEast;
		if (dir.equals(vNorth))
			return aNorth;
		if (dir.equals(vWest))
			return aWest;
		Vector3f vec = dir.clone();
		vec.setY(0);
		float angle = vec.angleBetween(vSouth);
		if (angle < 0)
			angle += FastMath.TWO_PI;
		return angle;
	}
	
	public static Vector3f vector(int dir){
		if (dir == iSouth)
			return vSouth;
		if (dir == iEast)
			return vEast;
		if (dir == iNorth)
			return vNorth;
		if (dir == iWest)
			return vWest;
		return null;
	}
	
	public static Vector3f vector(float dir){
		if (dir == aSouth)
			return vSouth;
		if (dir == aEast)
			return vEast;
		if (dir == aNorth)
			return vNorth;
		if (dir == aWest)
			return vWest;
		return new Vector3f(FastMath.cos(dir), 0, FastMath.sin(dir));
	}
}
